package com.itheima.d1_exception;

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age<0||age>150) {
            //年龄数据不合法，抛出一个异常提醒上层逻辑
            throw new AgeException("年龄必须在0到150岁之间");
        }
        this.age = age;
    }
}
